home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 3273.ZIP / VGAKIT52.ZIP / BANKS.ASM next >
Assembly Source File  |  1992-10-21  |  21KB  |  1,242 lines

  1.  
  2.     include    model.inc
  3.     include    vesa.inc
  4. ;
  5. ;    VGAKIT Version 5.2b
  6. ;
  7. ;    Copyright 1988,89,90,91,92 John Bridges
  8. ;    Free for use in commercial, shareware or freeware applications
  9. ;
  10. ;    BANKS.ASM
  11. ;
  12. .data?
  13.  
  14.     public    curbk
  15.  
  16. curbk    dw    ?
  17.  
  18.     public    vgamem,bksize
  19.  
  20. vgamem    dw    ?        ;amount of memory on VGA card in K
  21. bksize    dw    ?        ;size of memory banks in K
  22.  
  23.     public    cirrus,everex,acumos,paradise,tseng,trident,t8900
  24.     public    ativga,aheada,aheadb,oaktech,video7
  25.     public    chipstech,tseng4,genoa,ncr,compaq,vesa,dactype
  26.  
  27. cirrus    dw    ?
  28. everex    dw    ?
  29. acumos    dw    ?
  30. paradise dw    ?
  31. tseng    dw    ?
  32. trident    dw    ?
  33. t8900    dw    ?
  34. ativga    dw    ?
  35. aheada    dw    ?
  36. aheadb    dw    ?
  37. oaktech    dw    ?        ;Oak Technology Inc OTI-067 and OTI-077
  38. video7    dw    ?
  39. chipstech dw    ?
  40. tseng4    dw    ?
  41. genoa    dw    ?
  42. ncr    dw    ?
  43. compaq    dw    ?
  44. vesa    dw    ?
  45.  
  46. dactype    dw    ?        ; 0 = Normal DAC
  47.                 ; 1 = Sierra SC11481, SC11486, SC11488
  48.                 ; 2 = Sierra SC11485, SC11487, SC11489
  49.                 ; 3 = AT&T ATT20C491
  50.                 ; 4 = ACUMOS ADAC1
  51.  
  52. first    dw    ?        ;flag so whichvga() is only called once
  53. retval    dw    ?        ;first return value from whichvga()
  54.  
  55. .data
  56.  
  57. OSEG    equ    DS:        ;segment override for variable access
  58.  
  59.     public    bankadr
  60.  
  61. if @Codesize
  62. bankadr    dw    offset _nobank
  63.     dw    seg _nobank
  64. else
  65. bankadr    dw    offset _nobank
  66. endif
  67.  
  68.     public    vesafunc
  69.  
  70. vesafunc dw    0
  71.     dw    0
  72.  
  73. vesamodes label word
  74.     dw    100h,     640, 400, 8
  75.     dw    101h,     640, 480, 8
  76.     dw    102h,     800, 600, 4
  77.     dw    103h,     800, 600, 8
  78.     dw    104h,    1024, 768, 4
  79.     dw    105h,    1024, 768, 8
  80.     dw    106h,    1280,1024, 4
  81.     dw    107h,    1280,1024, 8
  82.     dw    10Dh,     320, 200,16
  83.     dw    10Eh,     320, 200,16
  84.     dw    10Fh,     320, 200,24
  85.     dw    110h,     640, 480,16
  86.     dw    111h,     640, 480,16
  87.     dw    112h,     640, 480,24
  88.     dw    113h,     800, 600,16
  89.     dw    114h,     800, 600,16
  90.     dw    115h,     800, 600,24
  91.     dw    116h,    1024, 768,16
  92.     dw    117h,    1024, 768,16
  93.     dw    118h,    1024, 768,24
  94.     dw    119h,    1280,1024,16
  95.     dw    11Ah,    1280,1024,16
  96.     dw    11Bh,    1280,1024,24
  97.     dw    0
  98. .code
  99.  
  100.     public    newbank
  101.     public    whichvga
  102.  
  103. newbank    proc            ;bank number is in AX
  104. if @Codesize
  105.     jmp    dword ptr OSEG[bankadr]
  106. else
  107.     jmp    OSEG[bankadr]
  108. endif
  109.  
  110. _tseng::            ;Tseng 3000 series
  111.     push    ax
  112.     push    dx
  113.     cli
  114.     mov    OSEG[curbk],ax
  115.     and    al,7
  116.     mov    ah,al
  117.     shl    al,1
  118.     shl    al,1
  119.     shl    al,1
  120.     or    al,ah
  121.     or    al,01000000b
  122.     mov    dx,3cdh
  123.     out    dx,al
  124.     sti
  125.     pop    dx
  126.     pop    ax
  127.     ret
  128.  
  129.  
  130. _tseng4::            ;Tseng 4000 series
  131.     push    ax
  132.     push    dx
  133.     cli
  134.     mov    OSEG[curbk],ax
  135.     mov    ah,al
  136.     mov    dx,3bfh        ;Enable access to extended registers
  137.     mov    al,3
  138.     out    dx,al
  139.     mov    dl,0d8h
  140.     mov    al,0a0h
  141.     out    dx,al
  142.     and    ah,15
  143.     mov    al,ah
  144.     shl    al,1
  145.     shl    al,1
  146.     shl    al,1
  147.     shl    al,1
  148.     or    al,ah
  149.     mov    dl,0cdh
  150.     out    dx,al
  151.     sti
  152.     pop    dx
  153.     pop    ax
  154.     ret
  155.  
  156.  
  157. _trident::            ;Trident
  158.     push    ax
  159.     push    dx
  160.     push    ax
  161.     cli
  162.     mov    OSEG[curbk],ax
  163.     mov    dx,3ceh        ;set pagesize to 64k
  164.     mov    al,6
  165.     out    dx,al
  166.     inc    dl
  167.     in    al,dx
  168.     dec    dl
  169.     or    al,4
  170.     mov    ah,al
  171.     mov    al,6
  172.     out    dx,ax
  173.  
  174.     mov    dl,0c4h        ;switch to BPS mode
  175.     mov    al,0bh
  176.     out    dx,al
  177.     inc    dl
  178.     in    al,dx
  179.     dec    dl
  180.  
  181.     pop    ax
  182.     mov    ah,al
  183.     xor    ah,2
  184.     mov    dx,3c4h
  185.     mov    al,0eh
  186.     out    dx,ax
  187.     sti
  188.     pop    dx
  189.     pop    ax
  190.     ret
  191.  
  192.  
  193. _video7::            ;Video 7
  194.     push    ax
  195.     push    dx
  196.     push    cx
  197.     cli
  198.     mov    OSEG[curbk],ax
  199.     and    ax,15
  200.     mov    ch,al
  201.     mov    dx,3c4h
  202.     mov    ax,0ea06h
  203.     out    dx,ax
  204.     mov    ah,ch
  205.     and    ah,1
  206.     mov    al,0f9h
  207.     out    dx,ax
  208.     mov    al,ch
  209.     and    al,1100b
  210.     mov    ah,al
  211.     shr    ah,1
  212.     shr    ah,1
  213.     or    ah,al
  214.     mov    al,0f6h
  215.     out    dx,al
  216.     inc    dx
  217.     in    al,dx
  218.     dec    dx
  219.     and    al,not 1111b
  220.     or    ah,al
  221.     mov    al,0f6h
  222.     out    dx,ax
  223.     mov    ah,ch
  224.     mov    cl,4
  225.     shl    ah,cl
  226.     and    ah,100000b
  227.     mov    dl,0cch
  228.     in    al,dx
  229.     mov    dl,0c2h
  230.     and    al,not 100000b
  231.     or    al,ah
  232.     out    dx,al
  233.     sti
  234.     pop    cx
  235.     pop    dx
  236.     pop    ax
  237.     ret
  238.  
  239.  
  240. _paradise::            ;Paradise
  241.     push    ax
  242.     push    dx
  243.     push    ax
  244.     cli
  245.     mov    OSEG[curbk],ax
  246.     mov    dx,3ceh
  247.     mov    ax,50fh        ;turn off write protect on VGA registers
  248.     out    dx,ax
  249.     pop    ax
  250.     mov    ah,al
  251.     mov    al,9
  252.     out    dx,ax
  253.     sti
  254.     pop    dx
  255.     pop    ax
  256.     ret
  257.  
  258. _acumos::            ;AcuMos
  259.     push    ax
  260.     push    dx
  261.     push    ax
  262.     cli
  263.     mov    OSEG[curbk],ax
  264.     mov    dx,3c4h        ;Sequencer index 6
  265.     mov    ax,1206h    ;turn off write protect on VGA registers
  266.     out    dx,ax
  267.     mov    dx,3ceh
  268.     pop    ax
  269.     mov    ah,al
  270.     mov    al,9
  271.     out    dx,ax
  272.     sti
  273.     pop    dx
  274.     pop    ax
  275.     ret
  276.  
  277.  
  278. _chipstech::            ;Chips & Tech
  279.     push    ax
  280.     push    dx
  281.     push    ax
  282.     cli
  283.     mov    OSEG[curbk],ax
  284.     mov    dx,46e8h    ;place chip in setup mode
  285.     mov    ax,1eh
  286.     out    dx,ax
  287.     mov    dx,103h        ;enable extended registers
  288.     mov    ax,0080h
  289.     out    dx,ax
  290.     mov    dx,46e8h    ;bring chip out of setup mode
  291.     mov    ax,0eh
  292.     out    dx,ax
  293.     pop    ax
  294.     mov    ah,al
  295.     mov    al,10h
  296.     mov    dx,3d6h
  297.     out    dx,ax
  298.     sti
  299.     pop    dx
  300.     pop    ax
  301.     ret
  302.  
  303.  
  304. _ativga::            ;ATI VGA Wonder
  305.     push    ax
  306.     push    dx
  307.     cli
  308.     mov    OSEG[curbk],ax
  309.     mov    ah,al
  310.     mov    dx,1ceh
  311.     mov    al,0b2h
  312.     out    dx,al
  313.     inc    dl
  314.     in    al,dx
  315.     shl    ah,1
  316.     and    al,0e1h
  317.     or    ah,al
  318.     mov    al,0b2h
  319.     dec    dl
  320.     out    dx,ax
  321.     sti
  322.     pop    dx
  323.     pop    ax
  324.     ret
  325.  
  326.  
  327. _everex::            ;Everex
  328.     push    ax
  329.     push    dx
  330.     push    cx
  331.     cli
  332.     mov    OSEG[curbk],ax
  333.     mov    cl,al
  334.     mov    dx,3c4h
  335.     mov    al,8
  336.     out    dx,al
  337.     inc    dl
  338.     in    al,dx
  339.     dec    dl
  340.     shl    al,1
  341.     shr    cl,1
  342.     rcr    al,1
  343.     mov    ah,al
  344.     mov    al,8
  345.     out    dx,ax
  346.     mov    dl,0cch
  347.     in    al,dx
  348.     mov    dl,0c2h
  349.     and    al,0dfh
  350.     shr    cl,1
  351.     jc    nob2
  352.     or    al,20h
  353. nob2:    out    dx,al
  354.     sti
  355.     pop    cx
  356.     pop    dx
  357.     pop    ax
  358.     ret
  359.  
  360.  
  361. _aheada::            ;Ahead Systems Ver A
  362.     push    ax
  363.     push    dx
  364.     push    cx
  365.     cli
  366.     mov    OSEG[curbk],ax
  367.     mov    ch,al
  368.     mov    dx,3ceh        ;Enable extended registers
  369.     mov    ax,200fh
  370.     out    dx,ax
  371.     mov    dl,0cch        ;bit 0
  372.     in    al,dx
  373.     mov    dl,0c2h
  374.     and    al,11011111b
  375.     shr    ch,1
  376.     jnc    skpa
  377.     or    al,00100000b
  378. skpa:    out    dx,al
  379.     mov    dl,0cfh        ;bits 1,2,3
  380.     mov    al,0
  381.     out    dx,al
  382.     inc    dx
  383.     in    al,dx
  384.     dec    dx
  385.     and    al,11111000b
  386.     or    al,ch
  387.     mov    ah,al
  388.     mov    al,0
  389.     out    dx,ax
  390.     sti
  391.     pop    cx
  392.     pop    dx
  393.     pop    ax
  394.     ret
  395.  
  396.  
  397. _aheadb::            ;Ahead Systems Ver A
  398.     push    ax
  399.     push    dx
  400.     push    cx
  401.     cli
  402.     mov    OSEG[curbk],ax
  403.     mov    ch,al
  404.     mov    dx,3ceh        ;Enable extended registers
  405.     mov    ax,200fh
  406.     out    dx,ax
  407.     mov    ah,ch
  408.     mov    cl,4
  409.     shl    ah,cl
  410.     or    ah,ch
  411.     mov    al,0dh
  412.     out    dx,ax
  413.     sti
  414.     pop    cx
  415.     pop    dx
  416.     pop    ax
  417.     ret
  418.  
  419.  
  420. _oaktech::            ;Oak Technology Inc OTI-067 and OTI-077
  421.     push    ax
  422.     push    dx
  423.     cli
  424.     mov    OSEG[curbk],ax
  425.     and    al,15
  426.     mov    ah,al
  427.     shl    al,1
  428.     shl    al,1
  429.     shl    al,1
  430.     shl    al,1
  431.     or    ah,al
  432.     mov    al,11h
  433.     mov    dx,3deh
  434.     out    dx,ax
  435.     sti
  436.     pop    dx
  437.     pop    ax
  438.     ret
  439.  
  440. _genoa::            ;GENOA GVGA
  441.     push    ax
  442.     push    dx
  443.     cli
  444.     mov    OSEG[curbk],ax
  445.     mov    ah,al
  446.     shl    al,1
  447.     shl    al,1
  448.     shl    al,1
  449.     or    ah,al
  450.     mov    al,6
  451.     or    ah,40h
  452.     mov    dx,3c4h
  453.     out    dx,ax
  454.     sti
  455.     pop    dx
  456.     pop    ax
  457.     ret
  458.  
  459. _ncr::                ;NCR 77C22E
  460.     push    ax
  461.     push    dx
  462.     cli
  463.     mov    OSEG[curbk],ax
  464.     mov    ah,al
  465.     mov    al,18h
  466.     mov    dx,3c4h
  467.     out    dx,ax
  468.     mov    ax,19h
  469.     out    dx,ax
  470.     sti
  471.     pop    dx
  472.     pop    ax
  473.     ret
  474.  
  475. _compaq::            ;Compaq
  476.     push    ax
  477.     push    dx
  478.     push    ax
  479.     cli
  480.     mov    OSEG[curbk],ax
  481.     mov    dx,3ceh
  482.     mov    ax,50fh        ;unlock extended registers
  483.     out    dx,ax
  484.     pop    ax
  485.     mov    ah,al
  486.     mov    al,45h
  487.     out    dx,ax
  488.     sti
  489.     pop    dx
  490.     pop    ax
  491.     ret
  492.  
  493. _vesa::                ;Vesa SVGA interface
  494.     push    ax
  495.     push    bx
  496.     push    dx
  497.     cli
  498.     mov    OSEG[curbk],ax
  499.     mov    dx,ax
  500.     xor    bx,bx
  501.     call    dword ptr OSEG[vesafunc]
  502.     mov    dx,OSEG[curbk]
  503.     mov    bx,1
  504.     call    dword ptr OSEG[vesafunc]
  505.     sti
  506.     pop    dx
  507.     pop    bx
  508.     pop    ax
  509.     ret
  510.  
  511. _nobank::
  512.     cli
  513.     mov    OSEG[curbk],ax
  514.     sti
  515.     ret
  516.  
  517. newbank    endp
  518.  
  519. bkadr    macro    func
  520.     mov    [func],1
  521.     mov    word ptr [bankadr],offset _&func
  522. if @Codesize
  523.     mov    word ptr [bankadr+2],seg _&func
  524. endif
  525.     endm
  526.  
  527. nojmp    macro
  528.     local    lbl
  529.     jmp    lbl
  530. lbl:
  531.     endm
  532.  
  533. dummyvesa proc    far
  534.     ret
  535. dummyvesa endp
  536.  
  537. whichvga proc    uses si di es
  538.     local    vesabuf[512]:byte    ; extra large to make up for
  539.                     ; bugs in some VESA VBE's
  540.  
  541.     cmp    [first],'FI'
  542.     jnz    gotest
  543.     mov    ax,[retval]
  544.     ret
  545. gotest:    mov    word ptr [bankadr],offset _nobank
  546. if @Codesize
  547.     mov    word ptr [bankadr+2],seg _nobank
  548. endif
  549.     mov    [vgamem],256
  550.     mov    [bksize],64
  551.     xor    ax,ax
  552.     mov    [curbk],ax
  553.     mov    [cirrus],ax
  554.     mov    [everex],ax
  555.     mov    [paradise],ax
  556.     mov    [tseng],ax
  557.     mov    [trident],ax
  558.     mov    [t8900],ax
  559.     mov    [ativga],ax
  560.     mov    [aheada],ax
  561.     mov    [aheadb],ax
  562.     mov    [oaktech],ax
  563.     mov    [video7],ax
  564.     mov    [chipstech],ax
  565.     mov    [tseng4],ax
  566.     mov    [genoa],ax
  567.     mov    [ncr],ax
  568.     mov    [compaq],ax
  569.     mov    [vesa],ax
  570.     mov    [dactype],ax
  571.     mov    [first],'FI'
  572.  
  573.     mov    si,1            ;flag for SVGA found
  574.  
  575.     mov    ax,ss
  576.     mov    es,ax
  577.     lea    di,vesabuf[0]
  578.     mov    ax,4f00h
  579.     int    10h
  580.     cmp    ax,4fh
  581.     jnz    novesa
  582.     mov    [bksize],64        ; (for now)
  583.     mov    [vesafunc],offset dummyvesa
  584.     mov    [vesafunc+2],cs
  585.     bkadr    vesa
  586.     mov    si,offset vesamodes
  587.     cld
  588. vesalp:    lodsw
  589.     mov    cx,ax
  590.     jcxz    endvesa
  591.     mov    ax,ss
  592.     mov    es,ax
  593.     lea    di,vesabuf[0]
  594.     mov    ax,4f01h        ;is mode available?
  595.     int    10h
  596.     or    ah,ah
  597.     jnz    notmode
  598.     test    byte ptr es:[di],1
  599.     jz    notmode            ;if mode not available skip mem size
  600.     lodsw
  601.     mov    cx,ax
  602.     lodsw
  603.     mov    bx,ax
  604.     lodsw
  605.     mul    cx            ;multiple by bits per pixel
  606.     shr    dx,1            ;shift right 3 times to get # of bytes
  607.     rcr    ax,1
  608.     shr    dx,1
  609.     rcr    ax,1
  610.     shr    dx,1
  611.     rcr    ax,1
  612.     mul    bx            ;multiply by number of scanlines
  613.     mov    bx,1024
  614.     add    ax,bx            ;round up to nearest kilobyte
  615.     dec    ax
  616.     adc    dx,0
  617.     div    bx
  618.     cmp    ax,[vgamem]        ;if mode requires more memory
  619.     jbe    vesalp
  620.     mov    [vgamem],ax        ;increase amount of vga memory
  621.     mov    ax,vesabuf.vesamode.WinSize
  622.     mov    [bksize],ax
  623.     jmp    short vesalp
  624. notmode:
  625.     add    si,6            ;skip to next mode in list
  626.     jmp    short vesalp
  627. endvesa:
  628.     mov    ax,[vgamem]
  629.     inc    ah
  630.     dec    ax
  631.     mov    al,0            ;round up to nearest 256k
  632.     cmp    ax,1024
  633.     jb    nomegs
  634.     add    ax,1023            ;round up to nearest megabyte
  635.     and    ax,not 1023
  636. nomegs:    mov    [vgamem],ax
  637.  
  638. ;    jmp    fini            ;uncomment to disable other tests if VESA VBE found
  639.  
  640. novesa:    mov    ax,0c000h        ;ATI VGA detect (largely from ATI example code)
  641.     mov    es,ax
  642.     cmp    word ptr es:[40h],'13'    ;ATI Signiture on the Video BIOS
  643.     jnz    noati
  644.     bkadr    ativga
  645.     mov    [bksize],64        ; 64k bank size
  646.     mov    dx,es:[10h]        ; Get value of ATI extended register
  647.     mov    bl,es:[43h]        ; Get value of ATI chip version
  648.     cmp    bl,'3'
  649.     jae    v6up            ; Use different method to determine
  650.     mov    al,0bbh         ; memory size of chip version is 3 or higher
  651.     cli
  652.     out    dx,al
  653.     inc    dx
  654.     in    al,dx            ; Get ramsize byte for chip versions 1 & 2
  655.     sti
  656.     test    al,20h
  657.     jz    no512
  658.     mov    [vgamem],512
  659.     jmp    short no512
  660.  
  661. v6up:    mov    al,0b0h            ; Method used for newer ATI chip versions
  662.     cli
  663.     out    dx,al
  664.     inc    dx
  665.     in    al,dx            ; Get ramsize byte for versions 3-5
  666.     sti
  667.     test    al,10h            ; Check if ramsize byte indicates 256K or 512K bytes
  668.     jz    v7up
  669.     mov    [vgamem],512
  670. v7up:    cmp    bl,'4'            ; Check for ramsize for ATI chip versions 4 & 5
  671.     jb    no512
  672.     test    al,8            ; Check if version 5 ATI chip has 1024K
  673.     jz    no512
  674.     mov    [vgamem],1024
  675. no512:    jmp    fini
  676.  
  677. noati:    mov    ax,7000h        ;Test for Everex
  678.     xor    bx,bx
  679.     cld
  680.     int    10h
  681.     cmp    al,70h
  682.     jnz    noev
  683.     bkadr    everex
  684.     mov    [bksize],64        ; 64k bank size
  685.     and    ch,11000000b        ;how much memory on board
  686.     jz    skp
  687.     mov    [vgamem],512
  688. skp:                    ;fall through for Everex boards using Trident or Tseng4000
  689.  
  690. noev:    mov    ax,0bf03h        ;Test for Compaq
  691.     xor    bx,bx
  692.     mov    cx,bx
  693.     int    10h
  694.     cmp    ax,0bf03h
  695.     jnz    nocp
  696.     test    cl,40h            ;is 640x480x256 available?
  697.     jz    nocp
  698.     bkadr    compaq
  699.     mov    [bksize],4        ; 4k bank size
  700.     mov    [vgamem],512
  701.     jmp    fini
  702.  
  703. nocp:    mov    dx,3c4h            ;Test for NCR 77C22E
  704.     mov    ax,0ff05h
  705.     call    _isport2
  706.     jnz    noncr
  707.     mov    ax,5            ;Disable extended registers
  708.     out    dx,ax
  709.     mov    ax,0ff10h        ;Try to write to extended register 10
  710.     call    _isport2        ;If it writes then not NCR
  711.     jz    noncr
  712.     mov    ax,105h            ;Enable extended registers
  713.     out    dx,ax
  714.     mov    ax,0ff10h
  715.     call    _isport2
  716.     jnz    noncr            ;If it does NOT write then not NCR
  717.     bkadr    ncr
  718.     mov    [bksize],16        ; 16k bank size
  719.     mov    [vgamem],512
  720.     jmp    fini
  721.  
  722. noncr:    mov    dx,3c4h            ;Test for Trident
  723.     mov    al,0bh
  724.     out    dx,al
  725.     inc    dl
  726.     in    al,dx
  727.     and    al,0fh
  728.     cmp    al,06h
  729.     ja    notri
  730.     cmp    al,2
  731.     jb    notri
  732.     bkadr    trident
  733.     mov    [bksize],64        ; 64k bank size
  734.     cmp    al,3
  735.     jb    no89
  736.     mov    [t8900],1
  737.     mov    dx,3d4h
  738.     mov    al,1fh
  739.     out    dx,al
  740.     inc    dx
  741.     in    al,dx
  742.     and    ax,3
  743.     inc    al
  744.     xchg    al,ah
  745.     mov    [vgamem],ax
  746.     jmp    fini
  747.  
  748. no89:    mov    [vgamem],512
  749.     jmp    fini
  750.  
  751. notri:    mov    ax,6f00h        ;Test for Video 7
  752.     xor    bx,bx
  753.     cld
  754.     int    10h
  755.     cmp    bx,'V7'
  756.     jnz    nov7
  757.     bkadr    video7
  758.     mov    [bksize],64        ; 64k bank size
  759.     mov    ax,6f07h
  760.     cld
  761.     int    10h
  762.     and    ah,7fh
  763.     cmp    ah,1
  764.     jbe    skp2
  765.     mov    [vgamem],512
  766. skp2:    cmp    ah,3
  767.     jbe    skp3
  768.     mov    [vgamem],1024
  769. skp3:    jmp    fini
  770.  
  771. nov7:    mov    dx,3d4h            ;Test for GENOA GVGA
  772.     mov    al,2eh            ;check for Herchi Register top 6 bits
  773.     out    dx,al
  774.     inc    dx
  775.     in    al,dx
  776.     dec    dx
  777.     test    al,11111100b        ;top 6 bits should be zero
  778.     jnz    nogn
  779.     mov    ax,032eh        ;check for Herchi Register
  780.     call    _isport2
  781.     jnz    nogn
  782.     mov    dx,3c4h
  783.     mov    al,7
  784.     out    dx,al
  785.     inc    dx
  786.     in    al,dx
  787.     dec    dx
  788.     test    al,10001000b
  789.     jnz    nogn
  790.     mov    al,10h
  791.     out    dx,al
  792.     inc    dx
  793.     in    al,dx
  794.     dec    dx
  795.     and    al,00110000b
  796.     cmp    al,00100000b
  797.     jnz    nogn
  798.     mov    dx,3ceh
  799.     mov    ax,0ff0bh
  800.     call    _isport2
  801.     jnz    nogn
  802.     mov    dx,3c4h            ;check for memory segment register
  803.     mov    ax,3f06h
  804.     call    _isport2
  805.     jnz    nogn
  806.     mov    dx,3ceh
  807.     mov    ax,0ff0ah
  808.     call    _isport2
  809.     jnz    nogn
  810.     bkadr    genoa
  811.     mov    [bksize],64        ; 64k bank size
  812.     mov    [vgamem],512
  813.     jmp    fini
  814.  
  815. nogn:    call    _cirrus            ;Test for Cirrus
  816.     cmp    [cirrus],0
  817.     je    noci
  818.     jmp    fini
  819.  
  820. noci:    mov    dx,3ceh            ;Test for Paradise
  821.     mov    al,9            ;check Bank switch register
  822.     out    dx,al
  823.     inc    dx
  824.     in    al,dx
  825.     dec    dx
  826.     or    al,al
  827.     jnz    nopd
  828.  
  829.     mov    ax,50fh            ;turn off write protect on VGA registers
  830.     out    dx,ax
  831.     mov    dx,offset _paradise
  832.     mov    cx,1
  833.     call    _chkbk
  834.     jc    nopd            ;if bank 0 and 1 same not paradise
  835.     bkadr    paradise
  836.     mov    [bksize],4        ; 4k bank size
  837.     mov    dx,3ceh
  838.     mov    al,0bh            ;512k detect from Bob Berry
  839.     out    dx,al
  840.     inc    dx
  841.     in    al,dx
  842.     test    al,80h            ;if top bit set then 512k
  843.     jz    nop512
  844.     test    al,40h
  845.     jz    nop1024
  846.     mov    [vgamem],1024
  847.     jmp    fini
  848. nop1024:
  849.     mov    [vgamem],512
  850. nop512:    jmp    fini
  851.  
  852. nopd:    mov    ax,5f00h        ;Test for Chips & Tech
  853.     xor    bx,bx
  854.     cld
  855.     int    10h
  856.     cmp    al,5fh
  857.     jnz    noct
  858.     bkadr    chipstech
  859.     mov    [bksize],16        ; 16k bank size
  860.     cmp    bh,1
  861.     jb    skp4
  862.     mov    [vgamem],512
  863. skp4:    jmp    fini
  864.  
  865. noct:    mov    dx,3dah            ;Test for Tseng 4000 & 3000
  866.     in    al,dx            ;bit 8 is opposite of bit 4
  867.     mov    ah,al            ;(vertical retrace bit)
  868.     shr    ah,1
  869.     shr    ah,1
  870.     shr    ah,1
  871.     shr    ah,1
  872.     xor    al,ah
  873.     test    al,00001000b
  874.     jz    nots
  875.     mov    dx,3d4h            ;check for Tseng 4000 series
  876.     mov    ax,0f33h
  877.     call    _isport2
  878.     jnz    not4
  879.     mov    ax,0ff33h        ;top 4 bits should not be there
  880.     call    _isport2
  881.     jz    nots
  882.  
  883.     mov    dx,3bfh            ;Enable access to extended registers
  884.     mov    al,3
  885.     out    dx,al
  886.     mov    dx,3d8h
  887.     mov    al,0a0h
  888.     out    dx,al
  889.     mov    al,0ffh
  890.     mov    dx,3cdh            ;test bank switch register
  891.     call    _isport1
  892.     jnz    not4
  893.     bkadr    tseng
  894.     mov    [bksize],64        ; 64k bank size
  895.     mov    ax,10f1h        ;Extended BIOS call to get DAC type on Tseng4000
  896.     int    10h
  897.     cmp    ax,10h
  898.     jnz    nodac
  899.     mov    bh,0
  900.     mov    [dactype],bx
  901. nodac:    mov    dx,3d4h            ;Tseng 4000 memory detect 1meg
  902.     mov    al,37h
  903.     out    dx,al
  904.     inc    dx
  905.     in    al,dx
  906.     test    al,1000b        ;if using 64kx4 RAMs then no more than 256k
  907.     jz    nomem
  908.     and    al,3
  909.     cmp    al,1            ;if 8 bit wide bus then only two 256kx4 RAMs
  910.     jbe    nomem
  911.     mov    [vgamem],512
  912.     cmp    al,2            ;if 16 bit wide bus then four 256kx4 RAMs
  913.     je    nomem
  914.     mov    [vgamem],1024        ;full meg with eight 256kx4 RAMs
  915. nomem:    bkadr    tseng4
  916.     mov    [bksize],64        ; 64k bank size
  917.     jmp    fini
  918.  
  919. not4:    mov    dx,3d4h            ;Test for Tseng 3000
  920.     mov    ax,1f25h        ;is the Overflow High register there?
  921.     call    _isport2
  922.     jnz    nots
  923.     mov    al,03fh            ;bottom six bits only
  924.     mov    dx,3cdh            ;test bank switch register
  925.     call    _isport1
  926.     jnz    nots
  927.     bkadr    tseng
  928.     mov    [bksize],64        ; 64k bank size
  929.     call    _t3memchk
  930.     jmp    fini
  931.  
  932. nots:    mov    dx,3ceh            ;Test for Ahead A or B chipsets
  933.     mov    ax,0ff0fh        ;register should not be fully available
  934.     call    _isport2
  935.     jz    noab
  936.     mov    ax,200fh
  937.     out    dx,ax
  938.     inc    dx
  939.     nojmp
  940.     in    al,dx
  941.     cmp    al,21h
  942.     jz    verb
  943.     cmp    al,20h
  944.     jnz    noab
  945.     bkadr    aheada
  946.     mov    [bksize],64        ; 64k bank size
  947.     mov    [vgamem],512
  948.     jmp    fini
  949.  
  950. verb:    bkadr    aheadb
  951.     mov    [bksize],64        ; 64k bank size
  952.     mov    [vgamem],512
  953.     jmp    fini
  954.  
  955. noab:    mov    dx,3c4h            ;Test for AcuMos chipsets
  956.     mov    ax,0006h        ;disable extended registers
  957.     out    dx,ax
  958.     mov    ax,0ff09h
  959.     call    _isport2        ;is scratchpad at index 9 writeable ?
  960.     jz    noacu
  961.     mov    ax,0ff0ah
  962.     call    _isport2        ;is scratchpad at index 10 writable ?
  963.     jz    noacu
  964.     mov    ax,1206h
  965.     out    dx,ax
  966.     mov    ax,0ff09h
  967.     call    _isport2
  968.     jnz    noacu
  969.     mov    ax,0ff0ah
  970.     call    _isport2
  971.     jnz    noacu
  972.     mov    dx,offset _acumos
  973.     mov    cx,1
  974.     call    _chkbk
  975.     jc    noacu            ;if bank 0 and 1 same not acumos
  976.     bkadr    acumos
  977.     mov    [bksize],4        ; 4k bank size
  978.     mov    dx,3c4h
  979.     mov    al,0ah
  980.     out    dx,al
  981.     inc    dx
  982.     in    al,dx            ;get scratchpad index 10
  983.     and    al,3
  984.     cmp    al,1
  985.     jb    noamem
  986.     mov    [vgamem],512
  987.     cmp    al,2
  988.     jb    noamem
  989.     mov    [vgamem],1024
  990.     cmp    al,3
  991.     jb    noamem
  992.     mov    [vgamem],2048
  993. noamem:    jmp    short fini
  994.  
  995. noacu:    mov    dx,3deh            ;Test for Oak Technology Inc OTI-067 and OTI-077
  996.     mov    ax,0ff11h        ;look for bank switch register
  997.     call    _isport2
  998.     jnz    nooak
  999.     bkadr    oaktech
  1000.     mov    [bksize],64        ; 64k bank size
  1001.     mov    al,0dh
  1002.     out    dx,al
  1003.     inc    dx
  1004.     nojmp
  1005.     in    al,dx
  1006.     test    al,11000000b
  1007.     jz    no4ram
  1008.     mov    [vgamem],512
  1009.     test    al,01000000b
  1010.     jz    no4ram
  1011.     mov    [vgamem],1024
  1012. no4ram:    jmp    short fini
  1013.  
  1014. nooak:
  1015.     mov    si,0
  1016.  
  1017. fini:    cmp    [vesa],0
  1018.     jz    novbank
  1019.     bkadr    vesa            ; Always use VESA bank switch
  1020.                     ; even if we have detected chipset
  1021. novbank:
  1022.     mov    ax,si
  1023.     mov    [retval],ax
  1024.     ret
  1025. whichvga endp
  1026.  
  1027.  
  1028. ;Segment to access video buffer (based on GR[6])
  1029. buftbl    dw    0A000h,0A000h,0B000h,0B800h
  1030.  
  1031. _t3memchk proc                ;[Charles Marslett -- ET3000 memory ck]
  1032.     mov    dx,3dah
  1033.     in    al,dx            ;Reset the attribute flop (read 0x3DA)
  1034.     mov    dx,03c0h
  1035.     mov    al,36h
  1036.     out    dx,al
  1037.     inc    dx
  1038.     in    al,dx            ;Save contents of ATTR[0x16]
  1039.     push    ax
  1040.     or    al,10h
  1041.     dec    dx
  1042.     out    dx,al
  1043.     mov    dx,3ceh            ;Find the RAM buffer...
  1044.     mov    al,6
  1045.     out    dx,al
  1046.     inc    dx
  1047.     in    al,dx
  1048.     and    ax,000Ch
  1049.     shr    ax,1
  1050.  
  1051.     mov    bx,ax
  1052.     push    es
  1053.     mov    es,cs:buftbl[bx]
  1054.     mov    ax,09C65h
  1055.     mov    bx,1
  1056.     mov    es:[bx],ax
  1057.     mov    es:[bx+2],ax
  1058.     inc    bx
  1059.     mov    ax,es:[bx]
  1060.     pop    es
  1061.     cmp    ax,0659Ch
  1062.     jne    et3k_256
  1063.     mov    [vgamem],512
  1064. et3k_256:
  1065.     mov    dx,3c0h
  1066.     mov    al,36h
  1067.     out    dx,al
  1068.     pop    ax
  1069.     out    dx,al            ;Restore ATTR[16h]
  1070.     ret
  1071. _t3memchk endp
  1072.  
  1073. _cirrus    proc    near
  1074.     mov    dx,3d4h        ; assume 3dx addressing
  1075.     mov    al,0ch        ; screen a start address hi
  1076.     out    dx,al        ; select index
  1077.     inc    dx        ; point to data
  1078.     mov    ah,al        ; save index in ah
  1079.     in    al,dx        ; get screen a start address hi
  1080.     xchg    ah,al        ; swap index and data
  1081.     push    ax        ; save old value
  1082.     push    dx        ; save crtc address
  1083.     xor    al,al        ; clear crc
  1084.     out    dx,al        ; and out to the crtc
  1085.  
  1086.     mov    al,1fh        ; Eagle ID register
  1087.     dec    dx        ; back to index
  1088.     out    dx,al        ; select index
  1089.     inc    dx        ; point to data
  1090.     in    al,dx        ; read the id register
  1091.     mov    bh,al        ; and save it in bh
  1092.  
  1093.     mov    cl,4        ; nibble swap rotate count
  1094.     mov    dx,3c4h        ; sequencer/extensions
  1095.     mov    bl,6        ; extensions enable register
  1096.  
  1097.     ror    bh,cl        ; compute extensions disable value
  1098.     mov    ax,bx        ; extensions disable
  1099.     out    dx,ax        ; disable extensions
  1100.     inc    dx        ; point to data
  1101.     in    al,dx        ; read enable flag
  1102.     or    al,al        ; disabled ?
  1103.     jnz    exit        ; nope, not an cirrus
  1104.  
  1105.     ror    bh,cl        ; compute extensions enable value
  1106.     dec    dx        ; point to index
  1107.     mov    ax,bx        ; extensions enable
  1108.     out    dx,ax        ; enable extensions
  1109.     inc    dx        ; point to data
  1110.     in    al,dx        ; read enable flag
  1111.     cmp    al,1        ; enabled ?
  1112.     jne    exit        ; nope, not an cirrus
  1113.     mov    [cirrus],1
  1114.     mov    word ptr [bankadr],offset _nobank
  1115. if @Codesize
  1116.     mov    word ptr [bankadr+2],seg _nobank
  1117. endif
  1118. exit:    pop    dx        ; restore crtc address
  1119.     dec    dx        ; point to index
  1120.     pop    ax        ; recover crc index and data
  1121.     out    dx,ax        ; restore crc value
  1122.     ret
  1123. _cirrus    endp
  1124.  
  1125. _chkbk    proc    near        ;bank switch check routine
  1126.     mov    di,0b800h
  1127.     mov    es,di
  1128.     xor    di,di
  1129.     mov    bx,1234h
  1130.     call    _gochk
  1131.     jnz    badchk
  1132.     mov    bx,4321h
  1133.     call    _gochk
  1134.     jnz    badchk
  1135.     clc
  1136.     ret
  1137. badchk:    stc
  1138.     ret
  1139. _chkbk    endp
  1140.  
  1141. calldx    macro
  1142. if @Codesize
  1143.     push    cs
  1144. endif
  1145.     call    dx
  1146.     endm
  1147.  
  1148. _gochk    proc    near
  1149.     push    si
  1150.     mov    si,bx
  1151.  
  1152.     mov    al,cl
  1153.     calldx
  1154.     xchg    bl,es:[di]
  1155.     mov    al,ch
  1156.     calldx
  1157.     xchg    bh,es:[di]
  1158.  
  1159.     xchg    si,bx
  1160.  
  1161.     mov    al,cl
  1162.     calldx
  1163.     xor    bl,es:[di]
  1164.     mov    al,ch
  1165.     calldx
  1166.     xor    bh,es:[di]
  1167.  
  1168.     xchg    si,bx
  1169.  
  1170.     mov    al,ch
  1171.     calldx
  1172.     mov    es:[di],bh
  1173.     mov    al,cl
  1174.     calldx
  1175.     mov    es:[di],bl
  1176.  
  1177.     mov    al,0
  1178.     calldx
  1179.     or    si,si
  1180.     pop    si
  1181.     ret
  1182. _gochk    endp
  1183.  
  1184. _isport2 proc    near        ;check for valid indexed i/o port, al is index, ah is bit mask
  1185.     push    bx
  1186.     mov    bx,ax
  1187.     out    dx,al
  1188.     mov    ah,al
  1189.     inc    dx
  1190.     in    al,dx
  1191.     dec    dx
  1192.     xchg    al,ah
  1193.     push    ax
  1194.     mov    ax,bx
  1195.     out    dx,ax
  1196.     out    dx,al
  1197.     mov    ah,al
  1198.     inc    dx
  1199.     in    al,dx
  1200.     dec    dx
  1201.     and    al,bh
  1202.     cmp    al,bh
  1203.     jnz    noport
  1204.     mov    al,ah
  1205.     mov    ah,0
  1206.     out    dx,ax
  1207.     out    dx,al
  1208.     mov    ah,al
  1209.     inc    dx
  1210.     in    al,dx
  1211.     dec    dx
  1212.     and    al,bh
  1213.     cmp    al,0
  1214. noport:    pop    ax
  1215.     out    dx,ax
  1216.     pop    bx
  1217.     ret
  1218. _isport2 endp
  1219.  
  1220. _isport1 proc    near        ;check for valid i/o port, al is bit mask
  1221.     mov    ah,al
  1222.     in    al,dx
  1223.     push    ax
  1224.     mov    al,ah
  1225.     out    dx,al
  1226.     in    al,dx
  1227.     and    al,ah
  1228.     cmp    al,ah
  1229.     jnz    noport
  1230.     mov    al,0
  1231.     out    dx,al
  1232.     in    al,dx
  1233.     and    al,ah
  1234.     cmp    al,0
  1235. noport:    pop    ax
  1236.     out    dx,al
  1237.     ret
  1238. _isport1 endp
  1239.  
  1240.     end
  1241.  
  1242.